﻿using MVBuddy.Common.Controls;
using System.Windows;
using System.Windows.Media.Imaging;

namespace MVBuddy.Common.Model
{
    public class UserData
    {
        private static TileBackBackgroundControl backBackground = new TileBackBackgroundControl();

        public string Username { get; set; }
        public string Password { get; set; }
        public NotificationData NotificationData { get; set; }
        public bool SaveLogin { get; set; }
        public bool EnableAgent { get; set; }
        public bool ShowToasts { get; set; }

        public UserData()
        {
            this.Username = string.Empty;
            this.Password = string.Empty;
            this.NotificationData = new NotificationData();
            this.SaveLogin = false;
            this.EnableAgent = false;
            this.ShowToasts = false;
        }

        public WriteableBitmap RenderUserDataForBackgroundTile()
        {
            TileData tileData = new TileData();
            tileData.UserData = this;
            backBackground.DataContext = tileData;
            backBackground.Measure(new Size(backBackground.Width, backBackground.Height));
            backBackground.Arrange(new Rect(0, 0, backBackground.Width, backBackground.Height));

            WriteableBitmap bitmap = new WriteableBitmap((int)(backBackground.Width * tileData.Scale), (int)(backBackground.Height * tileData.Scale));
            bitmap.Render(backBackground, new System.Windows.Media.ScaleTransform() { ScaleX = tileData.Scale, ScaleY = tileData.Scale });
            bitmap.Invalidate();

            return bitmap;
        }
    }
}
